<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css" media="all">
  <style type="text/css">
  .lable-box{
    font-family: '微软雅黑';
    font-size: 10;
  }
   .inputbox{
    padding: 15px; 
 }
</style>
</head>
<body>
  <div style="margin: 20px;">
<form class="layui-form">
<input type="hidden" name="id" value="{$courseclass.id|default=''}">
    <div class="layui-form-item">
    <label class="layui-form-label">学院:</label>
    <div class="layui-input-block">
      <select name="college_id" lay-verify="required" lay-filter="collegebtn">
      <option value="" ></option>
      <volist name="collegelst" id="vo">
        <option value="{$vo.id}"<if condition="$vo['name'] eq $courseclass['college_name']">selected</if>>{$vo.name}</option>
        </volist>
      </select>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">课程:</label>
    <div class="layui-input-block">
      <select name="lession_id" id="lession_id" lay-verify="required">
          <option value="{$courseclass['id']}"selected>{$courseclass.lession_name}</option>
      </select>
    </div>
  </div>

    <div class="layui-form-item">
    <label class="layui-form-label" >年级</label>
    <div class="layui-input-block">
      <select name="grade_id" lay-verify="required" lay-filter="grade" >
      <option value="" ></option>
      <volist name="gradelst" id="vo">
        <option value="{$vo.id}" <if condition="$vo['name'] eq $courseclass['grade_name']">selected</if>>{$vo.name}</option>
        </volist>
      </select>
    </div>
  </div>
    <div class="layui-form-item">
    <label class="layui-form-label  lable-box">任课老师:</label>
   <div class="layui-input-block">
      <select name="teacher_id" lay-verify="required" lay-filter="teacher" >
       <option value="" ></option>
      <volist name="teacherlist" id="vo">
        <option value="{$vo.id}" <if condition="$vo['name'] eq $courseclass['teacher_name']">selected</if>>{$vo.name}</option>
        </volist>
      </select>
    </div>
  </div>
          <label class="layui-form-label  lable-box">行课时间:</label>
            <div class="layui-form-pane">
          <div class="layui-input-inline">
              <input class="layui-input" placeholder="开始日期" id="start_time" name="start_time" style="height:30px; line-height:30px;"  value="{$courseclass.start_time|default=''}" readonly="true">
            </div>
            <div class="layui-input-inline">
              <input class="layui-input" placeholder="结束日期" id="end_time" name="end_time" style="height:30px; line-height:30px;" value="{$courseclass.end_time|default=''}" readonly="true">
            </div>
          </div>
  <div class="layui-form-item">
    <label class="layui-form-label  lable-box">班级名称:</label>
    <div class="layui-input-block">
      <input type="text" name="name" id="name" required  lay-verify="classname" placeholder="请输入班级名称" autocomplete="off" class="layui-input"  style="width:300px;" value="{$courseclass.name|default=''}">
   </div>
  </div>
  <div class="layui-form-item btn">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="class_btn">提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
</div>
<script src="__PUBLIC__/static/layui/layui.js"></script>
<script type="text/javascript">
  var editurl = "";
  if ('{$type}' == 'update'){
    editurl = "{:U('Home/courseclassMgr/updatecourseclass')}";
  }else if ('{$type}' == 'add_class'){
    editurl = "{:U('Home/courseclassMgr/add_courseclass')}";
  }
  var getlessionurl = "{:U('Home/courseclassMgr/getlession')}";
  var rooturl = "__ROOT__/";
</script>
<!-- <layuijs/> -->
</body>
</html>
<script type="text/javascript">
layui.use(['form','laydate'], function(){
  var form = layui.form(),
   laydate = layui.laydate,
  $ = layui.jquery;
  form.render(); //更新全部
  form.render('select');
 //监听提交
  var start = {
    istime: true, 
    format: 'YYYY-MM-DD', 
    festival: false,
      choose: function(datas){
        end.min = datas; //开始日选好后，重置结束日的最小日期
        end.start = datas //将结束日的初始值设定为开始日
      }
    };
    
    var end = {
      istime: true, 
    format: 'YYYY-MM-DD', 
    festival: false,
      choose: function(datas){
        start.max = datas; //结束日选好后，重置开始日的最大日期
      }
    };
    
    document.getElementById('start_time').onclick = function(){
      start.elem = this;
      laydate(start);
    }
    document.getElementById('end_time').onclick = function(){
      end.elem = this
      laydate(end);
    }
  //方法二
  form.on('select(collegebtn)', function(data){
        $.getJSON(getlessionurl+"?college_id="+data.value, function(data){
            var optionstring = "";
            if(data.data!=""){
            $.each(data.data, function(i,item){
                optionstring += "<option value=\"" + item.id + "\" >" + item.name + "</option>";
            });
            $("#lession_id").html('<option value=""></option>' + optionstring);
          }
          else{
            optionstring="<option value=\"" + 0 + "\" >" + "该学院下没有课程请重新选择!" + "</option>";
            $("#lession_id").html('<option value=""></option>' + optionstring);
          }
            form.render('select');
        });
  });
  form.on('submit(class_btn)', function(data) {
     // console.log(data.field);
    $.ajax({

      url: editurl,
      type: 'POST',
      data: data.field,
      error: function(request){
        layer.msg("请求服务器超时", {time: 1000, icon: 5});
      },
      success: function(data){
        if (data.success){
          layer.msg('提交成功', {
            time: 1000
          }, function(){
            parent.location.href="{:U('Home/courseclassMgr/courseclassList')}";
          });
        }else{
          layer.msg(data.msg, {
            time: 1000
          });
        }
      }
    });
    
    return false;
  });
});
</script>

